<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.qbt8.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 千佰特 <http://www.qbt8.com>
// +----------------------------------------------------------------------
namespace plugins\qbt_db_backup;
use cmf\lib\Plugin;
use think\Config;
use think\db;

class QbtDbBackupPlugin extends Plugin
{

    public $info = [
        'name'        => 'QbtDbBackup',
        'title'       => '数据库备份',
        'description' => '数据库备份',
        'status'      => 1,
        'author'      => '',
        'version'     => '1.0',
        'demo_url'    => '',
        'author_url'  => '',
    ];

    //操作日志url
    public $log = [
        'public/plugin/qbt_db_backup/admin_index/backup|备份数据库:{str}',
        'public/plugin/qbt_db_backup/admin_index/restore|还原数据库:{str}',
    ];

    public $hasAdmin = 1;//插件是否有后台管理界面

    // 插件安装
    public function install()
    {
        $config = Config::get('database');
        Db::query("DROP TABLE IF EXISTS `{$config['prefix']}backup`");
        Db::query("
            CREATE TABLE `{$config['prefix']}backup`  (
              `id` int(11) NOT NULL AUTO_INCREMENT,
              `create_time` int(10) NULL DEFAULT NULL COMMENT '备份时间',
              `table_num` int(11) NULL DEFAULT NULL,
              PRIMARY KEY (`id`) USING BTREE
            ) ENGINE = MyISAM;
        ");
        return true;
    }

    // 插件卸载
    public function uninstall()
    {
        $config = Config::get('database');
        Db::query("DROP TABLE `{$config['prefix']}backup`");
        return true;
    }
}